package com.shixun.six;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
import java.sql.*;
import java.util.Properties;

public class JDBCdbms {
//    static String url = "jdbc:mysql://localhost:3306/student?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true";
//    static String userName = "root";
//    static String userPasswd = "123456";
    static  String url, userName,userPasswd,driver;
    static {
        try {
            Properties pro=new Properties();
            ClassLoader classLoader=JDBCdbms.class.getClassLoader();
            URL url1=classLoader.getResource("jdbc.properties");
            String path=url1.getPath();
            pro.load(new FileReader(path));
            driver=pro.getProperty("driver");
            url=pro.getProperty("url");
            userName=pro.getProperty("userName");
            userPasswd=pro.getProperty("userPasswd");
            Class.forName("com.mysql.cj.jdbc.Driver");
            //Class.forName(driver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static Connection getConnection() throws SQLException {
        return DriverManager.getConnection(url,userName,userPasswd);
    }
}
